#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.


class SegmentTreeNode:
    def __init__(self, start, end, max):
        self.start, self.end, self.max = start, end, max
        self.left, self.right = None, None


class Solution:
    """
    @param root: The root of segment tree.
    @param index: index.
    @param value: value
    @return: nothing
    """

    # SEG_MIN = -1234567890

    def modify(self, root, index, value):
        self.modify_rec(root, index, value)

    def modify_rec(self, node, index, value):
        print(node.start, node.end)
        if node.end < index or node.start > index:
            # no overlap
            return node.max

        if node.start == index and node.end == index:
            node.max = value
        else:
            left_max  = self.modify_rec(node.left, index, value)
            right_max = self.modify_rec(node.right, index, value)
            # print('left_max %s' % left_max)
            # print('right_max %s' % right_max)
            node.max = max(left_max, right_max)
        return node.max


def main():
    print("start main")
    root = SegmentTreeNode(0, 1, 5)
    left = SegmentTreeNode(0, 0, 1)
    right = SegmentTreeNode(1, 1, 5)
    root.left, root.right = left, right

    s = Solution()
    s.modify(root, 0, 2)
    print(root.max)

if __name__ == "__main__":
    main()
